package com.huluobo.a2208kotlindouyindemo.shop

import androidx.lifecycle.MutableLiveData
import com.huluobo.base.bean.CommentBean
import com.huluobo.base.bean.GoodsBean
import com.huluobo.base.mvvm.BaseViewModel
import com.huluobo.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.RequestBody
import javax.inject.Inject

/**
 *  Created by LC on 2024/12/31.
 */
@HiltViewModel
class ShopViewModel @Inject constructor(
    val apiService: ApiService
) : BaseViewModel() {

    val getGoodsSuccess by lazy { MutableLiveData<List<GoodsBean>>() }
    fun getGoodsList(categoryId: Int, currentPage: Int, pageSize: Int) {
        executeNetwork(
            { apiService.getGoods(categoryId, currentPage, pageSize) },
            getGoodsSuccess::postValue
        )
    }

    val getGoodsDetailSuccess by lazy { MutableLiveData<GoodsBean>() }
    fun getGoodsDetail(goodsId: Int) {
        executeNetwork(
            { apiService.getGoodsDetail(goodsId) },
            getGoodsDetailSuccess::postValue
        )
    }

    val getCommentSuccess by lazy { MutableLiveData<List<CommentBean>>() }
    fun getComment(videoId: Int) {
        executeNetwork(
            { apiService.getComment(videoId) },
            getCommentSuccess::postValue
        )
    }

    val addCartSuccess by lazy { MutableLiveData<String>() }
    fun addToCart(body: RequestBody) {
        executeNetwork(
            { apiService.addToCart(body) },
            addCartSuccess::postValue
        )
    }
}